<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title>
<!--框架必需start-->
<script type="text/javascript" src="../../libs/js/jquery.js"></script>
<script type="text/javascript" src="../../libs/js/language/cn.js"></script>
<script type="text/javascript" src="../../libs/js/framework.js"></script>
<link href="../../libs/css/import_basic.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" type="text/css" id="skin" prePath="../../" scrollerY="false"/>
<link rel="stylesheet" type="text/css" id="customSkin"/>
<!--框架必需end-->

<!--树组件start -->
<script type="text/javascript" src="../../libs/js/tree/ztree/ztree.js"></script>
<link href="../../libs/js/tree/ztree/ztree.css" rel="stylesheet" type="text/css"/>
<!--树组件end -->

<!--布局控件start-->
<script type="text/javascript" src="../../libs/js/nav/layout.js"></script>
<!--布局控件end-->
</head>
<body>
<div id="layout1">
        <div position="center" style="" panelTitle="部门维护（菜单维护同理）">
        	<div id="orgContent" style="overflow-y: auto;">
			  <ul id="tree-1" class="ztree"></ul>
		  	</div>
        </div>
        <div position="right" style="" panelTitle="部门详情（如果是菜单，换成菜单功能描述和url设置）">
        	<div style="padding-left:5px;">
        	<table>
			<tr>
				<td>选中节点：</td>
				<td>
					<input type="text" style="width:300px;" id="selectNode" readOnly="true"/>
					<input type="hidden" id="selectNodeid"/>
				</td>
			</tr>
			<tr>
				<td>描述：</td>
				<td><input type="text" style="width:300px;" id="nodeDes"/></td>
			</tr>
			<tr>
				<td>负责人：</td>
				<td><input type="text" style="width:300px;" id="nodePerson"/></td>
			</tr>
			<tr>
				<td>电话：</td>
				<td><input type="text" style="width:300px;" id="nodePhone"/></td>
			</tr>
			<tr>
				<td colspan="2" class="ali02">
				<input type="button" id="btn_update" class="primary" value="确 定"/>
				</td>
			</tr>
			</table>
			</div>
        </div>
    </div> 



 
 <script type="text/javascript">

	 //树的设置
	 var setting1 = {
		view: {
			addHoverDom: addHoverDom,
			removeHoverDom: removeHoverDom,
			selectedMulti: false
		},
		edit: {
			enable: true,
			renameTitle:"修改",
			removeTitle:"删除"
		},
		callback: {
			onClick: onClick1,
			//不允许拖拽
			beforeDrag: beforeDrag1,
			//修改前确认
			beforeEditName: beforeEditName1,
			//修改完时的处理
			beforeRename: beforeRename1,
			//修改成功后处理
			onRename: onRename1,
			//删除前确认
			beforeRemove: beforeRemove1
		}};
	
	//定义树节点初始数据
	var zNodes1 =[{"id":"1","name":"南京分公司","icon":"../../libs/icons/user_group.gif","open":"true","parentId":"0","existed":true,"desc":"sdfsdf","manager":"张三","phone":"12345678911"},{"id":"2","name":"市场部","icon":"../../libs/icons/user_group.gif","open":"true","parentId":"1","existed":true,"desc":"","manager":"","phone":"215425"},{"id":"3","name":"市场1组","icon":"../../libs/icons/user_group.gif","open":"true","parentId":"2","existed":true,"desc":"111","manager":"廖轶宸","phone":"18600193618"},{"id":"7","name":"杭州办事处","icon":"../../libs/icons/user_group.gif","open":"true","parentId":"0","existed":true,"desc":"null","manager":"null","phone":"null"},{"id":"8","name":"接待处","icon":"../../libs/icons/user_group.gif","open":"true","parentId":"7","existed":true,"desc":"","manager":"傅凯","phone":"sdfsdf"},{"id":"9","name":"洽谈处","icon":"../../libs/icons/user_group.gif","open":"true","parentId":"7","existed":true,"desc":"","manager":"","phone":"士大夫"},{"id":"11","name":"市场2组","icon":"../../libs/icons/user_group.gif","open":"true","parentId":"2","existed":true,"desc":"null","manager":"null","phone":"null"},{"id":"12","name":"市场3组","icon":"../../libs/icons/user_group.gif","open":"true","parentId":"2","existed":true,"desc":"null","manager":"null","phone":"null"},{"id":"13","name":"财务部","icon":"../../libs/icons/user_group.gif","open":"true","parentId":"1","existed":true,"desc":"null","manager":"null","phone":"null"},{"id":"14","name":"行政部","icon":"../../libs/icons/user_group.gif","open":"true","parentId":"1","existed":true,"desc":"null","manager":"null","phone":"null"},{"id":"15","name":"工程部","icon":"../../libs/icons/user_group.gif","open":"true","parentId":"1","existed":true,"desc":"null","manager":"null","phone":"null"},{"id":"16","name":"技术部","icon":"../../libs/icons/user_group.gif","open":"true","parentId":"1","existed":true,"desc":"null","manager":"null","phone":"null"},{"id":"17","name":"生产部","icon":"../../libs/icons/user_group.gif","open":"true","parentId":"1","existed":true,"desc":"null","manager":"null","phone":"null"},{"id":"18","name":"工厂","icon":"../../libs/icons/user_group.gif","open":"true","parentId":"17","existed":true,"desc":"111","manager":"","phone":""}]
	
	//初始化函数
	function initComplete(){
		var layout=$("#layout1").layout({ rightWidth:650}); 
        //layout.setRightCollapse(true);

		//初始化树
		getOrgTreeData();
		
		
	}

	//获取数据初始化树
	function getOrgTreeData(){
		$.fn.zTree.init($("#tree-1"), setting1, zNodes1);
	}
	
	
	//获取树对象
	function getTree(){
		return $.fn.zTree.getZTreeObj("tree-1");
	}
	
	//点击
	function onClick1(event, treeId, treeNode, clickFlag){
    	//设置表单的值
    	setForm(treeNode.name,"","","frmright");
    }
	
	function beforeDrag1(treeId, treeNodes) {
		return false;
	}
	
	//确认是否进入编辑状态
	function beforeEditName1(treeId, treeNode) {
		if(treeNode.id=="1"){
			top.Toast("showNoticeToast", "根节点不能修改！");
			return false;
		}
		var zTree = $.fn.zTree.getZTreeObj("tree-1");
		//选中该节点
		zTree.selectNode(treeNode);
		//设置表单的值
		setForm(treeNode.name,"","","frmright");
		zTree.editName(treeNode);
		return true;
	}
	
	//修改完时处理 不进行后台数据处理
	function beforeRename1(treeId, treeNode, newName) {
		if (newName.length == 0) {
			top.Toast("showNoticeToast", "节点名称不能为空.");
			var zTree = $.fn.zTree.getZTreeObj("tree-1");
			setTimeout(function(){zTree.editName(treeNode)}, 10);
			return false;
		}
		return true;
	}
	//修改成功后处理
	function onRename1(event, treeId, treeNode) {
		//设置表单的值
		setForm(treeNode.name,"","","frmright");
		//此处进行ajax后台数据处理
	}
	
	//确认是否删除+删除处理
	function beforeRemove1(treeId, treeNode) {
		if(treeNode.id=="1"){
			top.Toast("showNoticeToast", "根节点不能删除！");
			return false;
		}
		var zTree = $.fn.zTree.getZTreeObj("tree-1");
		//选中该节点
		zTree.selectNode(treeNode);
		top.Dialog.confirm("确认删除 节点 -- " + treeNode.name + " 吗？",function(){
			zTree.removeNode(treeNode);
			//此处进行ajax后台数据处理
		});
		return false;
	}
	
	//添加新增按钮
	var newCount = 1;
	function addHoverDom(treeId, treeNode) {
	    if (treeNode.editNameFlag || $("#addBtn_" + treeNode.id).length > 0) return;
	    
		var sObj = $("#" + treeNode.tId + "_span");
		var addStr = "<span class='zbutton add' id='addBtn_" + treeNode.id + "' title='添加' onfocus='this.blur();'></span>";
		sObj.append(addStr);
		
		var btn = $("#addBtn_" + treeNode.id);
		if (btn){ 
		    btn.bind("click", function(){
				var zTree = $.fn.zTree.getZTreeObj("tree-1");
				var newNode;
				newNode = zTree.addNodes(treeNode, {id:(100 + newCount), parentId:treeNode.id, name:"新增" + (newCount++),icon:"../../libs/icons/mark.png"});
				if (newNode) {
					zTree.editName(newNode[0]);
					//设置表单的值
					//setForm(newNode[0].name,"","","frmright");
				}
				return false;
		   });
		}
	};
	function removeHoverDom(treeId, treeNode) {
		$("#addBtn_" + treeNode.id).unbind().remove();
	};
	
	
	function setForm(val1,val2,val3,val4){
		$("#selectNode").val(val1);
		$("#nodeDes").val(val2);
		$("#nodeUrl").val(val3);
		$("#nodeTarget").attr("editValue",val4);
		$("#nodeTarget").render();
	}
	
	function customHeightSet(contentHeight){
        $("#orgContent").height(contentHeight-40)
    }
 
 </script>

</body>
</html>